#include<bits/stdc++.h>
#define PI pair <int, int>
using namespace std;

int T;
int n, m, l, cs;
int d[100005], v[100005], a[100005], p[100005];
int vis[100005], vk[100005];
vector <int> k[100005];
struct Node
{
    vector <int> ki;
    int gs, z;
} mp[1000005];
priority_queue <PI> q;

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> T;
    while (T --)
    {
        while (!q.empty())
        {
            q.pop();
        }
        memset(vis, 0, sizeof(vis));
        memset(vk, 0, sizeof(vk));
        memset(mp, 0, sizeof(mp));
        cin >> n >> m >> l >> cs;
        for (int i = 1; i <= n; i ++)
        {
            k[i].clear();
        }
        for (int i = 1; i <= n; i ++)
        {
            cin >> d[i] >> v[i] >> a[i];
        }
        for (int i = 1; i <= m; i ++)
        {
            cin >> p[i];
        }
        int ans = 0;
        for (int i = 1; i <= n; i ++)
        {
            if (v[i] > cs)
            {
                if (a[i] >= 0)
                {
                    bool f = 0;
                    for (int j = 1; j <= m; j ++)
                    {
                        if (p[j] >= d[i])
                        {
                            f = 1;
                            k[i].push_back(j);
                            vis[j] = 1;
                        }
                    }
                    if (f) ans ++;
                    else vk[i] = 1;
                }
                else
                {
                    double o = floor((v[i] * v[i] * 1.0 - cs * cs * 1.0) / (2 * abs(a[i]) * 1.0) );
                    bool f = 0;
                    for (int j = 1; j <= m; j ++)
                    {
                        if (p[j] >= d[i] && p[j] <= d[i] + o)
                        {
                            f = 1;
                            k[i].push_back(j);
                            vis[j] = 1;
                        }
                    }
                    if (f) ans ++;
                    else vk[i] = 1;
                }
            }
            if (v[i] == cs)
            {
                if (a[i] > 0)
                {
                    bool f = 0;
                    for (int j = 1; j <= m; j ++)
                    {
                        if (p[j] > d[i])
                        {
                            f = 1;
                            k[i].push_back(j);
                            vis[j] = 1;
                        }
                    }
                    if (f) ans ++;
                    else vk[i] = 1;
                }
                else vk[i] = 1;
            }
            if (v[i] < cs)
            {
                if (a[i] > 0)
                {
                    double o = ceil((cs * cs * 1.0 - v[i] * v[i] * 1.0) / (2 * abs(a[i]) * 1.0) );
                    bool f = 0;
                    for (int j = 1; j <= m; j ++)
                    {
                        if (p[j] >= d[i] + o)
                        {
                            f = 1;
                            k[i].push_back(j);
                            vis[j] = 1;
                        }
                    }
                    if (f) ans ++;
                    else vk[i] = 1;
                }
                else vk[i] = 1;
            }
        }
        cout << ans << " ";
        ans = 0;
        memset(vis, 0, sizeof(vis));
        int l = INT_MIN;
        for (int i = 1; i <= n; i ++)
        {
            if (k[i].size() == 0) continue;
            if (k[i].size() ==  1)
            {
                l = max(l, k[i][0]);
                vis[k[i][0]] = 1;
                vk[i] = 1;
            }
        }
        bool ff = 0;
        for (int i = 1; i <= n; i ++)
        {
            ff = 0;
            for (int j = 0; j < k[i].size(); j ++)
            {
                for (int p = 1; p <= l; p ++)
                {
                    if (k[i][j] == p && vis[p] == 1)
                    {
                        vk[i] = 1;
                        ff = 1;
                        break;
                    }
                }
                if (ff) break;
            }
        }
        bool f = 1;
        for (int i = 1; i <= n; i ++)
        {
            if (!vk[i]) f = 0;
        }
        while (f == 0)
        {
            memset(mp, 0, sizeof(mp));
            int l = INT_MIN;
            for (int i = 1; i <= n; i ++)
            {
                if (vk[i]) continue;
                for (int j = 0; j < k[i].size(); j ++)
                {
                    mp[k[i][j]].gs ++;
                    q.push(make_pair(mp[k[i][j]].gs, k[i][j]));
                    mp[k[i][j]].ki.push_back(i);
                    l = max(l, k[i][j]);
                }
            }
            int p = q.top().second;
            vis[p] = 1;
            for (int i = 0; i < mp[p].ki.size(); i ++)
            {
                vk[mp[p].ki[i]] = 1;
            }
            f = 1;
            for (int i = 1; i <= n; i ++)
            {
                if (!vk[i]) f = 0;
            }
        }
        for (int i = 1; i <= m; i ++)
        {
            if (vis[i]) ans ++;
        }
        cout << m - ans << "\n";
    }
    return 0;
}
